/**
 * Copyright (C) 2018-2020
 * All rights reserved, Designed By www.yixiang.co
 * 注意：
 * 本软件为www.yixiang.co开发研制，未经购买不得使用
 * 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 * 一经发现盗用、分享等行为，将追究法律责任，后果自负
 */
package co.yixiang.modules.product.rest;


import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import co.yixiang.api.ApiResult;
import co.yixiang.api.YshopException;
import co.yixiang.common.aop.NoRepeatSubmit;
import co.yixiang.common.bean.LocalUser;
import co.yixiang.common.interceptor.AuthCheck;
import co.yixiang.constant.ShopConstants;
import co.yixiang.constant.SystemConfigConstants;
import co.yixiang.enums.AppFromEnum;
import co.yixiang.enums.ProductEnum;
import co.yixiang.enums.ShopCommonEnum;
import co.yixiang.logging.aop.log.AppLog;
import co.yixiang.modules.mp.config.WxMaConfiguration;
import co.yixiang.modules.order.service.YxStoreOrderCartInfoService;
import co.yixiang.modules.product.domain.*;
import co.yixiang.modules.product.param.YxStoreProductQueryParam;
import co.yixiang.modules.product.param.YxStoreProductRelationQueryParam;
import co.yixiang.modules.product.service.*;
import co.yixiang.modules.product.vo.*;
import co.yixiang.modules.services.CreatShareProductService;
import co.yixiang.modules.shop.domain.YxSystemAttachment;
import co.yixiang.modules.shop.service.YxSystemAttachmentService;
import co.yixiang.modules.shop.service.YxSystemConfigService;
import co.yixiang.modules.shop.service.YxSystemGroupDataService;
import co.yixiang.modules.user.domain.YxUser;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Maps;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品控制器
 * </p>
 *
 * @author hupeng
 * @since 2019-10-19
 */
@Slf4j
@RestController
@Api(value = "商学院模块", tags = "商城:商学院模块", description = "商学院模块")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class BusinessController {

    private final YxStoreProductService storeProductService;
    private final YxBusinessDetailService yxBusinessDetailService;
    private final YxBusinessTitleService yxBusinessTitleService;
    private final YxBusinessTypeService yxBusinessTypeService;
    private final YxSystemGroupDataService systemGroupDataService;
    private final YxStoreProductRelationService relationService;



    /**
     * 商学院详情
     */
    @AppLog(value = "商学院列表", type = 1)
    @AuthCheck
    @GetMapping("/business/queryAll")
    @ApiOperation(value = "商学院列表",notes = "商学院列表")
    public ApiResult<Map<String,Object>> queryAll()  {
        long uid = LocalUser.getUser().getUid();
        Map<String,Object> map = Maps.newHashMap();
        List<YxBusinessDetail> yxBusinessDetailList=yxBusinessDetailService.list();
        List<YxBusinessTitle> yxBusinessTitleList=yxBusinessTitleService.list(new LambdaQueryWrapper<YxBusinessTitle>().orderByDesc(YxBusinessTitle::getSort));
        List<YxBusinessType> yxBusinessTypeList=yxBusinessTypeService.list();
        List<JSONObject> businessSchoolBanner =systemGroupDataService.getDatas(ShopConstants.YSHOP_BUSINESSSCHOOL_BANNER);
        map.put("yxBusinessTypeList",yxBusinessTypeList);//商学院类型
        map.put("yxBusinessTitleList",yxBusinessTitleList);//商学院标题
        //map.put("yxBusinessDetailList",yxBusinessDetailList);//商学院明细
        map.put("businessSchoolBanner",businessSchoolBanner);//商学院轮播参数
        //添加足迹
        YxStoreProductRelation storeProductRelation = new YxStoreProductRelation();
        storeProductRelation.setProductId(new Long(1));
        storeProductRelation.setUid(uid);
        storeProductRelation.setCategory("商学院");
        storeProductRelation.setCreateTime(new Date());
        storeProductRelation.setType("foot");
        relationService.save(storeProductRelation);
        return ApiResult.ok(map);
    }

    /**
     * 商学院详情
     */
    @AppLog(value = "商学院详情", type = 1)
    @AuthCheck
    @GetMapping("/business/detail/{id}")
    @ApiOperation(value = "商学院详情",notes = "商学院详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商学院ID", paramType = "query", dataType = "long",required = true),
    })
    public ApiResult<Map<String,Object>> detail(@PathVariable long id)  {
        //long uid = LocalUser.getUser().getUid();
        Map<String,Object> map = Maps.newHashMap();
        List<YxBusinessDetail> yxBusinessDetailList=yxBusinessDetailService.getDetail(id);
        YxBusinessTitle title =yxBusinessTitleService.getById(id);
        map.put("yxBusinessDetailList",yxBusinessDetailList);//商学院明细
        map.put("title",title);//商学院主表
        return ApiResult.ok(map);
    }

    /**
     * 商学院明细详情
     */
    @AppLog(value = "商学院明细详情", type = 1)
    @AuthCheck
    @GetMapping("/businessDetail/detail/{id}")
    @ApiOperation(value = "商学院明细详情",notes = "商学院明细详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商学院明细ID", paramType = "query", dataType = "long",required = true),
    })
    public ApiResult<Map<String,Object>> businessDetail(@PathVariable long id)  {
        //long uid = LocalUser.getUser().getUid();
        Map<String,Object> map = Maps.newHashMap();
        YxBusinessDetail detail =yxBusinessDetailService.getById(id);
        map.put("detail",detail);//商学院明细
        return ApiResult.ok(map);
    }

}

